<template>
    <list-layout>
        <div slot="search">
            <div v-show="selTab==='1'">
                <el-form :model="queryParams" :inline="true" label-position="right" ref="queryForm" v-show="showSearch" label-width="88px">
                    <!-- 事业部 新增 -->
                    <el-form-item :label="$t('inspectionStandards.division')" prop="divisionName">
                        <division-dialog v-model="queryParams.divisionName"  />
                    </el-form-item>

                    <el-form-item :label="$t('inspectionManagement.materialName')" prop="materialName">
                        <el-input v-model="queryParams.materialName" :placeholder="
                      $t('public.placeholder', {
                        placeholder: $t('inspectionManagement.materialName'),
                      })
                    " size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item :label="$t('inventoryManagement.materialNo')" prop="materialCode">
                        <el-input v-model="queryParams.materialCode" :placeholder="
                      $t('public.placeholder', {
                        placeholder: $t('inventoryManagement.materialNo'),
                      })
                    " size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <!-- <el-form-item :label="$t('inventoryManagement.supplierNo')" prop="supplierCode">
                        <el-input v-model="queryParams.supplierCode" :placeholder="
                      $t('public.placeholder', {
                        placeholder: $t('inventoryManagement.supplierNo'),
                      })
                    " size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item> -->
                    <!-- <el-form-item :label="$t('inventoryManagement.materialType')" prop="materialType">
                        <el-autocomplete style="width:100%" size="small" popper-class="my-autocomplete" v-model="queryParams.materialType" :fetch-suggestions="materialTypeRemoteMethod" placeholder="请输入内容" @select="(e)=>handleMaterialTypeSelect(e,scope)">
                            <i class="el-icon-search el-input__icon" slot="suffix">
                            </i>
                            <template slot-scope="{ item }">
                                {{ item.typeName }}
                            </template>
                        </el-autocomplete>
                    </el-form-item> -->
                    <el-form-item :label="$t('inspectionManagement.plantArea')" prop="factoryCode">
                        <el-select v-model="queryParams.factoryCode" :placeholder="$t('public.select_holder',{select_holder: $t('inspectionManagement.plantArea')})" style="width:100%;" filterable clearable size="small">
                            <el-option v-for="(item) in factoryList" :key="item.plantCode" :label="item.plantName" :value="item.plantCode" />
                        </el-select>
                        <!-- <el-input v-model="queryParams.plantName" :placeholder="
                      $t('public.placeholder', {
                        placeholder: $t('inspectionManagement.plantArea'),
                      })
                    " size="small" @keyup.enter.native="handleQuery" /> -->
                    </el-form-item>
                  <!-- 工厂代码  -->
                  <el-form-item :label="$t('inspectionManagement.factoryCode')" prop="lot">
                    <el-input v-model="queryParams.factoryCodeLike" :placeholder="
                      $t('public.placeholder', {
                        placeholder: $t('inspectionManagement.factoryCode'),
                      })
                    " clearable size="small" />
                  </el-form-item>
                    <el-form-item :label="$t('public.status')" prop="status">
                        <el-select v-model="queryParams.status" style="width:190px" :placeholder="
                      $t('public.select_holder', {
                        select_holder: $t('public.status'),
                      })
                    " size="small">
                            <el-option key="" label="全部" value="" />
                            <el-option v-for="item in dict.type.NYIQC_PROOFREAD_STATUS" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>

                        </el-select>
                    </el-form-item>
                    <el-form-item :label="$t('public.creator')" prop="createBy">
                        <el-input v-model="queryParams.createBy" :placeholder="
                      $t('public.placeholder', {
                        placeholder: $t('public.creator'),
                      })
                    " size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item>

                    <!-- 基地 新增 -->
                    <el-form-item :label="$t('basicData.baseName')" prop="baseName">
                        <el-input v-model="queryParams.baseName" :placeholder="
                      $t('public.placeholder', {
                        placeholder: $t('basicData.baseName'),
                      })
                    " size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <!-- 车间 新增 -->
                    <el-form-item :label="$t('basicData.workshop')" prop="workshop">
                        <el-input v-model="queryParams.workshop" :placeholder="
                      $t('public.placeholder', {
                        placeholder: $t('basicData.workshop'),
                      })
                    " size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                </el-form>
                <div style="display: flex; justify-content: center">
                    <el-button type="primary" icon="el-icon-search" class="search" size="mini" @click="handleQuery">{{ $t("public.search") }}</el-button>
                    <el-button icon="el-icon-refresh" class="resectBtn" size="mini" @click="resetQuery">{{ $t("public.reset") }}</el-button>
                </div>
            </div>
            <div v-show="selTab==='2'">
                <el-form :model="queryParams" :inline="true" label-position="right" ref="queryForm2" v-show="showSearch" label-width="88px">
                    <!-- 数据源 隐藏 -->
                    <!-- <el-form-item label="数据源" prop="dataSource">
                        <el-select v-model="queryParams.dataSource" style="width:190px" :placeholder="
                        $t('public.select_holder', {select_holder: $t('数据源'),}) " clearable size="small">
                            <el-option key="" label="全部" value="" />
                            <el-option v-for="dict in dataSourceOptions" :key="dict.label" :label="dict.label" :value="dict.value" />
                        </el-select>
                    </el-form-item> -->
                    <el-form-item :label="$t('inspectionManagement.templateName')" prop="templateName">
                        <el-input v-model="queryParams.templateName" :placeholder="
                        $t('public.placeholder', {
                          placeholder: $t('inspectionManagement.templateName'),
                        })
                      " size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item label-width="100px" :label="$t('inspectionManagement.checkNewVersion')" prop="checkNewVersion">
                      <el-select v-model="queryParams.checkNewVersion" style="width:100%;" clearable size="small">
                        <el-option key="0" :label="$t('public.no')" value="0" />
                        <el-option key="1" :label="$t('public.yes')" value="1" />
                      </el-select>
                    </el-form-item>
                    <!-- 事业部  -->
                    <el-form-item :label="$t('inspectionStandards.division')" prop="divisionName">
                      <division-dialog v-model="queryParams.divisionName"  />
                    </el-form-item>
                </el-form>
                <div style="display: flex; justify-content: center">
                    <el-button type="primary" icon="el-icon-search" class="search" size="mini" @click="getTemplateList">{{ $t("public.search") }}</el-button>
                    <el-button icon="el-icon-refresh" class="resectBtn" size="mini" @click="resetTemplate">{{ $t("public.reset") }}</el-button>
                </div>
            </div>

        </div>
        <div>
            <div class="container-header">
                <div class="header-left">
                    {{ $t("inspectionStandards.standards") }}
                </div>
            </div>
            <el-row style="position: relative; top: 12px">
                <el-col :span="24">
                    <el-tabs v-model="selTab" @tab-click="handleTabClick" type="border-card">
                        <el-tab-pane name="1" :label="$t('inspectionStandards.standards')">

                            <el-row :gutter="10" class="mb8 btnGroup">
                                <el-col :span="1.5">
                                    <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['ny-iqc:inspectionPlan:add']">{{ $t("public.add") }}</el-button>
                                </el-col>
                                <el-col :span="1.5">
                                    <el-button type="primary" icon="el-icon-check" size="mini" @click="handleSubmit" v-hasPermi="['ny-iqc:inspectionPlan:getSubmit']">{{ $t("public.submit") }}</el-button>
                                </el-col>
                                <!-- 批量新增 移除 -->
                                <!-- <el-col :span="1.5">
                                    <el-button type="primary" icon="el-icon-check" v-hasPermi="['ny-iqc:inspectionPlan:addBatch']" size="mini" @click="batchAdd('add')">{{$t('inspectionManagement.batchAdd')}}</el-button>
                                </el-col> -->
                                <!-- 批量修改 移除 -->
                                <!-- <el-col :span="1.5">
                                    <el-button type="primary" icon="el-icon-check" v-hasPermi="['ny-iqc:inspectionPlan:editBatch']" size="mini" @click="batchEdit('edit')">{{$t('inspectionManagement.batchEdit')}}</el-button>
                                </el-col>  -->
                                <!-- <el-col :span="1.5">
                                    <el-button icon="el-icon-delete" size="mini" class="deleteitemBtn" v-hasPermi="['ny-iqc:inspectionPlan:remove']" @click="handleBatchDelete">{{$t('public.delete')}}</el-button>
                                </el-col>-->
                                <el-col :span="1.5">
                                    <el-button class="importitemBtn" size="mini" @click="handleImport2" v-hasPermi="['ny-iqc:inspectionPlan:import']"><img src="@/assets/images/icons/daoru.png" alt=""> {{$t('inventoryManagement.oneImport')}}</el-button>
                                </el-col>
                                <!-- <el-col :span="1.5">
                                    <el-button class="importitemBtn" size="mini" @click="handleImport3" v-hasPermi="['ny-iqc:inspectionPlan:import']"><img src="@/assets/images/icons/daoru.png" alt=""> {{$t('inventoryManagement.batchImport')}}</el-button>
                                </el-col>-->
                                <!-- <el-col :span="1.5">
                                    <el-button size="mini" class="exportitemBtn" @click="handleExport" v-hasPermi="['ny-iqc:inspectionPlan:export']"><img src="@/assets/images/icons/daochu.png" alt=""> {{$t('inspectionManagement.singleExport')}}</el-button>
                                </el-col>  -->
                                <el-col :span="1.5">
                                    <el-button size="mini" class="exportitemBtn" @click="handleExportList" v-hasPermi="['ny-iqc:inspectionPlan:export']"><img src="@/assets/images/icons/daochu.png" alt=""> {{$t('inspectionManagement.exportForm')}}</el-button>
                                </el-col>
                                <!--                                <el-col :span="1.5">-->
                                <!--                                    <el-button size="mini" class="importitemBtn" @click="handleCheckout" v-hasPermi="['ny-iqc:inspectionPlan:getProofread']"><img src="@/assets/images/icons/checkout.png" alt=""> {{ $t("inventoryManagement.completeProofreading") }}</el-button>-->
                                <!--                                </el-col>-->
                                <el-col :span="1.5">
                                    <el-button size="mini" v-hasPermi="['ny-iqc:inspectionPlan:getApproval']" class="exportitemBtn" @click="handleApprove"><img src="@/assets/images/icons/approve.png" alt="" />
                                        {{$t('inspectionManagement.approval')}}</el-button>
                                </el-col>
                                <el-col :span="1.5">
                                    <el-button size="mini" v-hasPermi="['ny-iqc:inspectionPlan:revokeApproval']" class="exportitemBtn" @click="handleRevokeApprove"><img src="@/assets/images/icons/revoke.png" alt="" />
                                        {{$t('inspectionManagement.revokeApproval')}}</el-button>
                                </el-col>
                                <!--                                <el-col :span="1.5">-->
                                <!--                                    <el-button size="mini" v-hasPermi="['ny-iqc:inspectionPlan:getSendBack']" class="return-Btn" @click="handleReturn"><img src="@/assets/images/icons/back.png" alt="" />-->
                                <!--                                        {{ $t("inspectionManagement.return") }}</el-button>-->
                                <!--                                </el-col>-->
                                <!--                                <el-col :span="1.5">-->
                                <!--                                    <el-button size="mini" class="importitemBtn" v-hasPermi="['ny-iqc:inspectionPlan:sendSAP']" @click="updateStatus">SAP</el-button>-->
                                <!--                                </el-col>-->
                                    <!-- 历史计划 -->
                                <el-col :span="1.5">
                                    <el-button size="mini" v-hasPermi="['iqc:inspectionPlan:getApproval']" class="exportitemBtn" @click="handleHistory"><img src="@/assets/images/icons/approve.png" alt="" />
                                        {{$t('fmeaDoc.versionCompare.dataHistory')}}</el-button>
                                </el-col>
                                <el-col :span="1.5">
                                    <el-button icon="el-icon-delete" size="mini" class="deleteitemBtn" v-hasPermi="['ny-iqc:inspectionPlan:remove']" @click="handleBatchDelete">{{$t('ncr.batchDelete')}}</el-button>
                                </el-col>
                                <right-toolbar ref="group2" :columns="columns" @callback="columnsCallback"></right-toolbar>
                                <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
                            </el-row>
                            <div class="container-table">
                                <el-table :height="tableHeight" border v-loading="loading" ref="multipleTable" :key="planKey" :data="planList" @selection-change="handlePlanChange" :row-class-name="tableRowClassName">
                                    <el-table-column type="selection" width="55" align="center" fixed="left" />
                                    <el-table-column :label="$t('public.serialNum')" type="index" align="center">
                                        <template slot-scope="scope">
                                            <span>{{
                        (queryParams.pageNum - 1) * queryParams.pageSize +
                        scope.$index +
                        1
                      }}</span>
                                        </template>
                                    </el-table-column>

                                    <el-table-column sortable :label="$t('public.status')" align="left" v-if="columns[0].visible" width="75" prop="status" :show-overflow-tooltip="true">
                                        <template slot-scope="scope">
                                            <span>{{statusfilter(scope.row)}}</span>
                                        </template>
                                    </el-table-column>
                                    <el-table-column sortable :label="$t('inventoryManagement.materialName')" v-if="columns[1].visible" align="left" width="200" prop="materialName" :show-overflow-tooltip="true" />
                                    <el-table-column sortable :label="$t('inventoryManagement.materialNo')" v-if="columns[2].visible" align="left" width="150" :show-overflow-tooltip="true" prop="materialCode" />
                                    <!-- <el-table-column sortable :label="$t('inventoryManagement.materialType')" v-if="columns[3].visible" align="left" width="100" :show-overflow-tooltip="true" prop="materialType" />
                                    <el-table-column sortable :label="$t('inventoryManagement.maturity')" v-if="columns[4].visible" width="100" align="left" :show-overflow-tooltip="true" prop="maturity" /> -->

                                    <!--                                    <el-table-column sortable :label="$t('inspectionManagement.effectDate')" v-if="columns[5].visible" align="left" width="140" prop="effectiveDate" :show-overflow-tooltip="true" />-->
                                    <el-table-column sortable :label="$t('inspectionManagement.version')" v-if="columns[6].visible" align="center" prop="version" width="100" />
                                    <!-- <el-table-column sortable :label="$t('inspectionManagement.notApprovalReason')" v-if="columns[7].visible" align="center" prop="rejectReason" width="180" :show-overflow-tooltip="true" /> -->
                                    <el-table-column sortable :label="$t('factory.factoryCode')" v-if="columns[8].visible" width="180" align="left" prop="factoryCode" :show-overflow-tooltip="true" />
                                    <el-table-column sortable :label="$t('inspectionManagement.factory')" v-if="columns[8].visible" width="180" align="left" prop="factoryName" :show-overflow-tooltip="true" />

                                    <!-- 事业部 新增 -->
                                    <el-table-column sortable :label="$t('inspectionStandards.division')" v-if="columns[14].visible" align="left" width="200" prop="divisionName" :show-overflow-tooltip="true" />
                                    <!-- 基地 新增 -->
                                    <el-table-column sortable :label="$t('basicData.baseName')" v-if="columns[15].visible" align="left" width="200" prop="baseName" :show-overflow-tooltip="true" />
                                    <!-- 车间 新增 -->
                                    <el-table-column sortable :label="$t('basicData.workshop')" v-if="columns[16].visible" align="left" width="200" prop="workshop" :show-overflow-tooltip="true" />

                                    <el-table-column sortable :label="$t('task.checkman')" v-if="columns[10].visible" align="center" prop="approving" width="120" :show-overflow-tooltip="true" />
                                    <!--                                    <el-table-column sortable :label="$t('inventoryManagement.supplierNo')" v-if="columns[11].visible" align="left" prop="supplierCode" width="120" :show-overflow-tooltip="true" />-->

                                    <!--                                    <el-table-column sortable :label="$t('inventoryManagement.supplierName')" v-if="columns[12].visible" align="left" prop="supplierName" width="200" :show-overflow-tooltip="true" />-->

                                    <el-table-column sortable :label="$t('public.createTime')" v-if="columns[13].visible" align="left" prop="createTime" width="140" :show-overflow-tooltip="true" />
                                    <el-table-column sortable :label="$t('inspectionManagement.description')" v-if="columns[9].visible" align="center" prop="planRemark" minWidth="140" :show-overflow-tooltip="true" />
                                    <el-table-column sortable :label="$t('public.opera')" fixed="right" align="center" width="180">
                                        <template slot-scope="scope">
                                            <div class="action-wrap">
                                                <table-body-btn type="delete" @click.native="handleDelete(scope.row)" v-hasPermi="['ny-iqc:inspectionPlan:remove']" />
                                                <table-body-btn type="gwview" :name="$t('home.view')" @click.native="handleView(scope.row)" v-hasPermi="['ny-iqc:inspectionPlan:getInfo']" />
                                                <table-body-btn :name="$t('inspectionManagement.upgrade')" type="copy" @click.native="handleCopy(scope.row)" v-hasPermi="['ny-iqc:inspectionPlan:getCopyId']" />
                                                <table-body-btn :name="$t('public.edit')" type="gwedit" @click.native="handleEdit(scope.row)" v-hasPermi="['ny-iqc:inspectionPlan:edit']" />
                                                <table-body-btn :name="$t('inspectionManagement.convertTemplate')" type="template" @click.native="handleTemplate(scope.row)" v-hasPermi="['ny-iqc:inspectionPlan:getTemplate']" />

                                                <table-body-btn type="transfer" :name="$t('inspectionManagement.split')" @click.native="handleSplit(scope.row)" v-hasPermi="['ny-iqc:checkItem:split']" />
                                            </div>
                                        </template>
                                    </el-table-column>
                                </el-table>

                                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" layout="total, sizes, prev, pager, next, jumper" />
                            </div>
                        </el-tab-pane>
                        <el-tab-pane name="2" :label="$t('inspectionStandards.standardsTemplate')">

                            <el-row :gutter="10" class="mb8 btnGroup">
                                <el-col :span="1.5">
                                    <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddTemplate" v-hasPermi="['ny-iqc:checkItem:add']">{{ $t("public.add") }}</el-button>
                                    <el-button type="primary" icon="el-icon-plus" size="mini" @click="handlePush" v-hasPermi="['ny-iqc:checkItem:add']">{{ $t("public.push") }}</el-button>
                                    <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleExportExcel" v-hasPermi="['ny-iqc:checkItem:add']">{{ $t("public.exportExcel") }}</el-button>
                                </el-col>
                                <!-- <el-col :span="1.5">
                                    <el-button class="importitemBtn" size="mini" @click="importTemplate" v-hasPermi="['ny-iqc:checkItem:import']"><img src="@/assets/images/icons/daoru.png" alt=""> {{$t('public.import')}}</el-button>
                                </el-col>
                                <el-col :span="1.5">
                                    <el-button size="mini" class="exportitemBtn" @click="handleExportTemplate" v-hasPermi="['ny-iqc:checkItem:export']"><img src="@/assets/images/icons/daochu.png" alt=""> {{$t('public.export')}}</el-button>
                                </el-col> -->
                                <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
                            </el-row>
                            <div class="container-table">
                                <el-table :height="tableHeight" border stripe v-loading="loading" :data="templateList" @selection-change="handleSelectionChange">
                                    <el-table-column type="selection" width="55" fixed="left" align="center" :show-overflow-tooltip="true"/>
                                    <el-table-column sortable :label="$t('public.serialNum')" type="index" align="center">
                                        <template slot-scope="scope">
                                            <span>{{
                                                (queryParams.pageNum - 1) * queryParams.pageSize +
                                                scope.$index +
                                                1
                                            }}</span>
                                        </template>
                                    </el-table-column>
                                    <!-- 数据源 移除 -->
                                    <!-- <el-table-column sortable :label="$t('inspectionManagement.dataSource')" align="center" min-width="100" prop="dataSource">
                                        <template slot-scope="scope">
                                            {{dataSourceFilter(scope.row)}}
                                        </template>
                                    </el-table-column> -->
                                    <el-table-column sortable :label="$t('inspectionManagement.templateName')" align="center" min-width="100" prop="templateName" />
                                    <el-table-column sortable :label="$t('inspectionManagement.description')" align="center" min-width="140" prop="description" />
                                    <el-table-column sortable :label="$t('inspectionManagement.checkNewVersion')" align="center" min-width="100" prop="checkNewVersion" >
                                      <template slot-scope="scope">
                                        <span v-if="scope.row.checkNewVersion == 1">{{$t('public.yes')}}</span>
                                        <span v-if="scope.row.checkNewVersion == 0">{{$t('public.no')}}</span>
                                      </template>
                                    </el-table-column>
                                    <el-table-column sortable :label="$t('inspectionManagement.newVersion')" align="center" min-width="140" prop="version" />
                                    <el-table-column sortable :label="$t('inspectionManagement.pushVersion')" align="center" min-width="100" prop="pushVersion" />
                                    <el-table-column sortable :label="$t('inspectionManagement.ssDivision')" align="center" min-width="100" prop="divisionName" />
                                    <el-table-column sortable :label="$t('public.opera')" fixed="right" align="center" width="140">
                                        <template slot-scope="scope">
                                            <div class="action-wrap">
                                                <!-- <table-body-btn type="delete" @click.native="handleDelete(scope.row)"    v-hasPermi="['system:message:remove']"/> -->
                                                <table-body-btn type="view" :name="$t('sop.changeRecord')" @click.native="handleTemplateVersion(scope.row)" v-hasPermi="['ny-iqc:checkItem:getInfo']" />
                                                <table-body-btn type="gwview" :name="$t('home.view')" @click.native="handleTemplateDetail(scope.row)" v-hasPermi="['ny-iqc:checkItem:getInfo']" />
                                                <table-body-btn type="gwedit" :name="$t('public.edit')" @click.native="handleEditTemplate(scope.row)" v-hasPermi="['ny-iqc:checkItem:edit']" />
                                                <table-body-btn type="copy" :name="$t('public.copy')" @click.native="handleCopyTemplate(scope.row)" v-hasPermi="['ny-iqc:checkItem:getCopy']" />
                                                <table-body-btn type="gwdelete" :name="$t('public.delete')" @click.native="handleTemplateDelete(scope.row)" v-hasPermi="['ny-iqc:checkItem:removeId']" />

                                            </div>
                                        </template>
                                    </el-table-column>
                                </el-table>

                                <pagination v-show="templateTotal > 0" :total="templateTotal" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getTemplateList" layout="total, sizes, prev, pager, next, jumper" />
                            </div>
                        </el-tab-pane>
                    </el-tabs>
                </el-col>
            </el-row>
            <!-- 审批 -->
            <el-dialog :title="$t('inventoryManagement.approval')" :visible.sync="auditOpen" center top="14vh" width="500px" append-to-body :fullscreen="fullscreen">
                <el-form :model="auditForm" ref="auditForm" label-position="top" :rules="auditRules">
                    <el-form-item :label="$t('inventoryManagement.isPassApproval')" prop="status">
                        <el-radio-group v-model="auditForm.status">
                            <el-radio label="2">{{
                      $t("inventoryManagement.pass")
                    }}</el-radio>
                            <el-radio label="3">{{
                      $t("inventoryManagement.reject")
                    }}</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item :label="$t('inventoryManagement.rejectReason')">
                        <el-input type="textarea" :placeholder="$t('public.placeholder', { placeholder: $t('inventoryManagement.rejectReason')})" v-model="auditForm.planRemark" maxlength="1000">
                        </el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="submitAudit" icon="el-icon-check" size="small">{{ $t("public.define") }}</el-button>
                </div>
            </el-dialog>
            <el-dialog :title="$t('inspectionManagement.copyTemplate')" :visible.sync="copyTemplateOpen" center top="34vh" width="500px" append-to-body :fullscreen="fullscreen">
                <el-form :model="copyTemplateForm" ref="copyTemplateForm" v-model="copyTemplateForm" label-position="top">
                    <el-form-item :label="$t('inspectionManagement.templateName')" prop="newName">
                        <el-input :placeholder="$t('public.placeholder',{placeholder: $t('inspectionManagement.templateName')})" v-model="copyTemplateForm.newName">
                        </el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="submitCopyTemplate" icon="el-icon-check" size="small">{{$t('public.define')}}</el-button>
                </div>
            </el-dialog>
            <!-- 退回 -->
            <el-dialog title="退回" :visible.sync="approvalOpen" center top="14vh" width="500px" append-to-body :fullscreen="fullscreen">
                <el-form :model="approvalForm" ref="approvalForm" label-position="top">
                    <el-form-item :label="$t('inventoryManagement.rejectReason')" prop="planRemark">
                        <el-input type="textarea" :placeholder="
                $t('public.placeholder', {
                  placeholder: $t('inventoryManagement.rejectReason'),
                })
              " v-model="approvalForm.planRemark" maxlength="1000">
                        </el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="submitApproval" icon="el-icon-check" size="small">{{ $t("public.define") }}</el-button>
                </div>
            </el-dialog>

            <!-- 转化模板 -->
            <el-dialog :title="$t('inspectionManagement.toTemplate')" :visible.sync="toTemplateOpen" center top="34vh" width="500px" append-to-body :fullscreen="fullscreen">
                <el-form :model="toTemplateModel" ref="toTemplateForm" label-position="top">
                    <el-form-item :label="$t('inspectionManagement.templateName')" prop="auditor">
                        <el-input v-model="toTemplateModel.templateName" :placeholder="$t('public.placeholder',{placeholder: $t('inspectionManagement.templateName')})" size="small" />
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="submitToTemplate" icon="el-icon-check" size="small">{{$t('public.define')}}</el-button>
                </div>
            </el-dialog>
            <input v-show="false" ref="excel-upload-input" class="excel-upload-input" type="file" accept=".xlsx,xls" @change="handleClick">
            <import-dialog :visible.sync="templateVisible" @callback="uploadCallback" :action="'/ny-iqc/inspectionPlan/import'" :templateUrl="'/static/inspectionPlan.xlsx'" />
            <import-dialog :visible.sync="templateVisible2" @callback="uploadTemplateCallback" :action="'/ny-iqc/checkItem/import'" :templateUrl="'/static/inspectionTemplate.xlsx'" />
            <import-dialog :visible.sync="templateVisible3" @callback="uploadCallback2" :action="'/ny-iqc/inspectionPlan/import2'" :templateUrl="'/static/inspectionPlan3.xlsx'" />
            <import-dialog :visible.sync="templateVisible33" ref="templateVisible33" @callback="uploadCallback2" :action="'/ny-iqc/inspectionPlan/import3'" :templateUrl="'/static/inspectionPlan3.xlsx'" />
            <template-dialog :visible.sync="templateVisibleAll" @callback="(row)=>templateDataCallback(row)" />
            <!-- 审批 -->
            <el-dialog title="提交" :visible.sync="submitOpen" center top="14vh" width="500px" append-to-body :fullscreen="fullscreen">
                <el-form :model="submitForm" ref="submitForm" label-position="top" :rules="approveRules">
                    <!-- <el-form-item :label="$t('inventoryManagement.isPassApproval')" prop="approveStatus">
                        <el-radio-group v-model="submitForm.approveStatus" @change="radioChange">
                            <el-radio label="0">{{
                $t("inventoryManagement.pass")
              }}</el-radio>
                            <el-radio label="1">{{
                $t("inventoryManagement.reject")
              }}</el-radio>
                        </el-radio-group>
                    </el-form-item> -->
                    <!-- <el-form-item :label="$t('inventoryManagement.rejectReason')" prop="supplierBatchNo">
                        <el-popover placement="right" width="400" trigger="click">
                            <el-table :data="tipsData" :show-header="false" @row-click="tipsClick">
                                <el-table-column property="title" label="建议" :show-overflow-tooltip="true"></el-table-column>
                            </el-table>
                            <el-input type="textarea" slot="reference" :placeholder="
                $t('public.placeholder', {
                  placeholder: $t('inventoryManagement.rejectReason'),
                })
              " v-model="approvalForm.rejectReason" maxlength="1000">
                            </el-input>
                        </el-popover>

                    </el-form-item> -->
                    <el-form-item label="选择审批人" prop="informPeoplesName">
                        <select-user-dialog :multiple="true" v-model="submitForm.approving" @callback="(row) => userDataCallback(row)" />
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="submitInspection" icon="el-icon-check" size="small">{{ $t("public.define") }}</el-button>
                </div>
            </el-dialog>
              <!-- 历史版本 -->
            <el-dialog :title="$t('fmeaDoc.versionCompare.dataHistory')" :visible.sync="historyOpen" center top="14vh" width="1400px" :fullscreen="fullscreen" :modal-append-to-body="false">
                <div class="container-table">
                    <el-table :height="tableHeight" border v-loading="historyLoading" ref="historyTable" :key="planKey" :data="planHistoryList" :row-class-name="tableRowClassName">
                        <el-table-column :label="$t('public.serialNum')" type="index" align="center">
                            <template slot-scope="scope">
                                <span>{{
                                    (queryParams.pageNum - 1) * queryParams.pageSize +
                                    scope.$index +
                                    1
                                    }}</span>
                            </template>
                        </el-table-column>
                        <!-- <el-table-column sortable :label="$t('public.status')" align="left" v-if="columns[0].visible" width="75" prop="status" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span>{{statusfilter(scope.row)}}</span>
                            </template>
                        </el-table-column> -->
                        <el-table-column sortable :label="$t('inventoryManagement.materialName')" v-if="columns[1].visible" align="left" width="200" prop="materialName" :show-overflow-tooltip="true" />
                        <el-table-column sortable :label="$t('inventoryManagement.materialNo')" v-if="columns[2].visible" align="left" width="150" :show-overflow-tooltip="true" prop="materialCode" />
                        <!-- <el-table-column sortable :label="$t('inventoryManagement.materialType')" v-if="columns[3].visible" align="left" width="100" :show-overflow-tooltip="true" prop="materialType" />
                        <el-table-column sortable :label="$t('inventoryManagement.maturity')" v-if="columns[4].visible" width="100" align="left" :show-overflow-tooltip="true" prop="maturity" /> -->

                        <!--                                    <el-table-column sortable :label="$t('inspectionManagement.effectDate')" v-if="columns[5].visible" align="left" width="140" prop="effectiveDate" :show-overflow-tooltip="true" />-->
                        <el-table-column sortable :label="$t('inspectionManagement.version')" v-if="columns[6].visible" align="center" prop="version" width="100" />
                        <!-- <el-table-column sortable :label="$t('inspectionManagement.notApprovalReason')" v-if="columns[7].visible" align="center" prop="rejectReason" width="180" :show-overflow-tooltip="true" /> -->
                        <el-table-column sortable :label="$t('inspectionManagement.factory')" v-if="columns[8].visible" width="180" align="left" prop="factoryName" :show-overflow-tooltip="true" />
                        <!-- 事业部 新增 -->
                        <el-table-column sortable :label="$t('inspectionStandards.division')" v-if="columns[14].visible" align="left" width="200" prop="divisionName" :show-overflow-tooltip="true" />
                        <!-- 基地 新增 -->
                        <el-table-column sortable :label="$t('basicData.baseName')" v-if="columns[15].visible" align="left" width="200" prop="baseName" :show-overflow-tooltip="true" />
                        <!-- 车间 新增 -->
                        <el-table-column sortable :label="$t('basicData.workshop')" v-if="columns[16].visible" align="left" width="200" prop="workshop" :show-overflow-tooltip="true" />

                        <el-table-column sortable :label="$t('public.creator')" v-if="columns[10].visible" align="center" prop="createBy" width="120" :show-overflow-tooltip="true" />
                        <!--                                    <el-table-column sortable :label="$t('inventoryManagement.supplierNo')" v-if="columns[11].visible" align="left" prop="supplierCode" width="120" :show-overflow-tooltip="true" />-->

                        <!--                                    <el-table-column sortable :label="$t('inventoryManagement.supplierName')" v-if="columns[12].visible" align="left" prop="supplierName" width="200" :show-overflow-tooltip="true" />-->

                        <!-- <el-table-column sortable :label="$t('public.createTime')" v-if="columns[13].visible" align="left" prop="createTime" width="140" :show-overflow-tooltip="true" /> -->
                        <!-- <el-table-column sortable :label="$t('inspectionManagement.description')" v-if="columns[9].visible" align="center" prop="planRemark" minWidth="140" :show-overflow-tooltip="true" /> -->
                        <el-table-column sortable :label="$t('public.opera')" fixed="right" align="center" width="80">
                            <template slot-scope="scope">
                                <div class="action-wrap">
                                    <table-body-btn type="gwview" :name="$t('home.view')" @click.native="handleView(scope.row)" v-hasPermi="['iqc:inspectionPlan:getInfo']" />
                                </div>
                            </template>
                        </el-table-column>
                    </el-table>

                    <pagination v-show="historyTotal > 0" :total="historyTotal" :page.sync="historyQueryParams.pageNum" :limit.sync="historyQueryParams.pageSize" @pagination="getHistoryList" layout="total, sizes, prev, pager, next, jumper" />
                </div>
                <div slot="footer" class="dialog-footer">
                    <el-button icon="el-icon-close" size="small" @click="historyOpen = false" class="drawer-close">{{$t('public.close')}}</el-button>
                </div>
            </el-dialog>
          <el-dialog :visible="visible" :title="$t('变更记录')" width="1000px" append-to-body top="14vh"
                     class="knowledge-dialog" :close-on-click-modal="false">
            <div class="container-table">
              <el-table max-height="350" border stripe :data="templateVersionTableList"
                        @selection-change="handleSelectionChange">
                <el-table-column :label="$t('fmeaProject.version')" align="left" prop="version" minWidth="160"/>
                <el-table-column :label="$t('stepSymbol.updateTime')" align="left" prop="createTime" minWidth="160"/>
                <el-table-column :label="$t('public.changes')" align="center" width="100">
                  <template slot-scope="scope">
                    <a class="action-wrap" @click="choose(scope.row)" style="color:#5a9eaf">
                      {{$t('public.referTo')}}
                    </a>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div slot="footer">
              <el-button size="mini" type="default" icon="el-icon-close" @click="handleConfirm">{{
                  $t("btn.close")
                }}
              </el-button>
            </div>
          </el-dialog>
        </div>
    </list-layout>
</template>

<script>
import {getType, refreshCache} from '@/api/basic/dict/type'
import {
  deletePlan,
  getApproval,
  getApprovalInspectionCheck,
  getHistoryPlan,
  getProofread,
  getSendBack,
  getSubmit,
  importPlan,
  inspectionPlan,
  inspectionPlanEditCheck,
  listTemplate,
  planCopy,
  planToTemplate,
  splitInspection,
  templateCopy,
  templateDelete,
  updateStatus,
  getTemplateVersion,
  getTemplateInfoByVersion,
  push,
  revokeApprove
} from '@/api/inspectionManagement/inspectionManagement'
import FileUploadInput from '@/components/FileUploadInput'
import SelectUserDialog from '@/views/components/SelectUserDialog'
import {listAllFactory} from '@/api/basic/factory'
import importDialog from '../../components/importDialog'
import TemplateDialog from '@/views/components/TemplateDialog'
import {listMaterialType} from '@/api/basic/materialtype'
import {mapState} from 'vuex'
import DivisionDialog from '@/views/components/DivisionDialog'
import {postDownload} from "../../../utils/request";
import { divisionList } from '@/api/masterdata/division'

export default {
    name: 'inspectionPlan',
    dicts: ['NYIQC_PROOFREAD_STATUS'],
    components: {
        FileUploadInput,
        importDialog,
        TemplateDialog,
        SelectUserDialog,
        DivisionDialog
    },
    data() {
        return {
            templateVersionTableList:[],
            templateVisible33:false,
            direction: 'rtl',
            selTab: '1',
            templateVisibleAll: false,
            submitOpen: false,
            historyOpen: false, // 历史版本弹窗
            factoryList: [],
            approvalForm: {
                rejectReason: null,
            },
            auditForm: {},
            planKey: 0,
            columns: [
                { key: 0, label: this.$t('public.status'), visible: true },
                {
                    key: 1,
                    label: this.$t('inventoryManagement.materialName'),
                    visible: true,
                },
                {
                    key: 2,
                    label: this.$t('inventoryManagement.materialNo'),
                    visible: true,
                },
                {
                    key: 3,
                    label: this.$t('inventoryManagement.materialType'),
                    visible: true,
                },
                {
                    key: 4,
                    label: this.$t('inventoryManagement.maturity'),
                    visible: true,
                },
                {
                    key: 5,
                    label: this.$t('inspectionManagement.effectDate'),
                    visible: true,
                },
                {
                    key: 6,
                    label: this.$t('inspectionManagement.version'),
                    visible: true,
                },
                {
                    key: 7,
                    label: this.$t('inspectionManagement.notApprovalReason'),
                    visible: true,
                },
                {
                    key: 8,
                    label: this.$t('inspectionManagement.factory'),
                    visible: true,
                },
                {
                    key: 9,
                    label: this.$t('public.remark'),
                    visible: true,
                },
                {
                    key: 10,
                    label: this.$t('public.creator'),
                    visible: true,
                },

                {
                    key: 11,
                    label: this.$t('inventoryManagement.supplierNo'),
                    visible: true,
                },
                {
                    key: 12,
                    label: this.$t('inventoryManagement.supplierName'),
                    visible: true,
                },
                {
                    key: 13,
                    label: '创建时间',
                    visible: true,
                },
                { key: 14, label: this.$t('inspectionStandards.division'), visible: true },
                { key: 15, label: this.$t('basicData.baseName'), visible: true },
                { key: 16, label: this.$t('basicData.workshop'), visible: true },
            ],
            tableHeight: 'calc(100vh - 498px)',
            templateVisible2: false,
            templateVisible3: false,
            approvalOpen: false,
            templateVisible: false,
            visible: false,
            addInspectionExemption: false,
            toTemplateOpen: false,
            toTemplateModel: {},
            drawer: false,
            copyTemplateOpen: false,
            auditOpen: false,
            templateList: [],
            submitForm: {
                approving: null,
                approvingId: null,
            },
            templateTotal: 0,
            viewInspectionExemption: false,
            dataSourceOptions: [
                {
                    value: '1',
                    label: '来料',
                },
                {
                    value: '2',
                    label: '库存',
                },
            ],
            inspectionOptions: [
                {
                    value: '1',
                    label: '检验项1',
                },
                {
                    value: '2',
                    label: '检验项2',
                },
            ],
            inspectionTypeUnitOptions: [
                {
                    value: '1',
                    label: '单位1',
                },
                {
                    value: '2',
                    label: '单位2',
                },
            ],
            frequencyOptions: [
                {
                    value: '1',
                    label: '批',
                },
                {
                    value: '2',
                    label: '件',
                },
                {
                    value: '3',
                    label: '年',
                },
                {
                    value: '4',
                    label: '季',
                },
                {
                    value: '5',
                    label: '月',
                },
            ],
            samplingSchemeOptions: [
                {
                    value: '1',
                    label: 'GB/T2828.1-2012',
                },
                {
                    value: '2',
                    label: '百分比',
                },
                {
                    value: '3',
                    label: '固定抽样',
                },
                {
                    value: '4',
                    label: 'C=0',
                },
            ],
            testMethodOptions: [
                {
                    value: '1',
                    label: '目测',
                },
                {
                    value: '2',
                    label: '量具',
                },
                {
                    value: '3',
                    label: '验证',
                },
            ],
            samplingLevelOptions: [
                {
                    value: '1',
                    label: 'S-1',
                },
                {
                    value: '2',
                    label: 'S-2',
                },
                {
                    value: '3',
                    label: 'S-3',
                },
                {
                    value: '4',
                    label: 'S-4',
                },
            ],
            samplingLevelTypeOptions: [
                {
                    value: '1',
                    label: '正常',
                },
                {
                    value: '2',
                    label: '放宽',
                },
                {
                    value: '3',
                    label: '加严',
                },
            ],
            samplingFixedTypeOptions: [
                {
                    value: '1',
                    label: '批',
                },
                {
                    value: '2',
                    label: '件',
                },
            ],
            specialCharacteristicsOptions: [
                {
                    value: '1',
                    label: 'CC',
                },
                {
                    value: '2',
                    label: 'SC',
                },
            ],
            inspecStatus: [
                { label: '全部', value: '' },
                { label: '待校对', value: '0' },
                { label: '待审批', value: '1' },
                { label: '审批通过', value: '2' },
                { label: '审批不通过', value: '3' },
            ],
            addModel: {},
            viewModel: {
                file: 'xxx.jpeg',
            },
            editModel: {},
            copyTemplateForm: {
                newName: '',
            },
            selBtn: 1,
            // 遮罩层
            loading: false,
            // 选中数组
            ids: [],
            templateNames: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 1,
            // 字典表格数据
            planList: [],
            // 检验标准历史版本 相关属性
            planHistoryList: [], // 检验标准历史版本列表
            historyTotal: 1,
            historyLoading: false,
            historyQueryParams: {
                pageNum: 1,
                pageSize: 10,
            },
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 日期范围
            dateRange: [],
            selectRows: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                materialName: '',
                supplierName: '',
                supplierCode: '',
                factoryName: '',
                materialCode: '',
                status: '',
                templateName: undefined,
                materialType: undefined,
                createBy: '',
                divisionName: '', // 事业部
                baseName: '', //  基地
                workshop: '', // 车间
            },
            operaType: 'add',
            // 表单参数
            form: {},
            // 表单校验
            auditRules: {
                status: [
                    {
                        required: true,
                        message: '状态不能为空',
                        trigger: 'blur',
                    },
                ],
                planRemark: [
                    {
                        required: true,
                        message: '备注不能为空',
                        trigger: 'blur',
                    },
                ],
            },
            rules: {
                materialName: [
                    {
                        required: true,
                        message: this.$t('formValidation.materialNameCannotBeEmpty'),
                        trigger: 'blur',
                    },
                ],
                materialNo: [
                    {
                        required: true,
                        message: '物料编号不能为空',
                        trigger: 'blur',
                    },
                ],
                supplierNo: [
                    {
                        required: true,
                        message: '供应商编号不能为空',
                        trigger: 'blur',
                    },
                ],
            },
            fullscreen: false,
            approveRules: {},
        }
    },
    mounted() {
        let planColumns = JSON.parse(localStorage.getItem('planColumns'))

        console.log(planColumns)
        if (planColumns) {
            this.columns = JSON.parse(planColumns)
        }
        if (this.$route.query.uniqueId) {
            this.queryParams.id = this.$route.query.uniqueId
        }
        this.getList(true)
        this.getTemplateList()
        this.getFactoryList()
    },
    activated() {
        if (this.$route.query.uniqueId) {
            this.queryParams.id = this.$route.query.uniqueId
        }
        this.getList()
        this.getFactoryList()
        this.getTemplateList()
    },
    computed: {
        ...mapState({
            isFold: (state) => state.app.isFold,
        }),
    },
    watch: {
        isFold(val) {
            if (val === true) {
                this.tableHeight = 'calc(100vh - 358px)'
            } else {
                this.tableHeight = 'calc(100vh - 498px)'
            }
        },
    },
    methods: {
      choose(row) {
        this.visible = false
        this.$router.push({
          path:
              '/templateDetail/index/' +
              encodeURIComponent(row.templateName),
          query: {
            isView: 1,
            groupId: row.templateGroupId,
            version: row.version,
          },
        })
      },
      // 窗口关闭
      handleConfirm() {
        this.visible = false
      },
        handleTabClick() {
            this.queryParams = {
                pageSize: 10,
                pageNum: 1,
            }
        },
        submitInspection() {
            if (!this.submitForm.approving) {
                this.$modal.msgError('请选审批人!')
                return
            }
            this.submitOpen = false
            this.submitForm.ids = this.ids.join(',')

            getSubmit(this.submitForm).then((response) => {
                this.$modal.msgSuccess('提交成功')
                this.getList()
            })
        },
        userDataCallback(userId) {
            this.submitForm.approvingId = userId
            this.$refs.submitForm.validateField('approving')
        },
        // 数据源
        dataSourceFilter(row) {
            if (row.dataSource) {
                let io = this.dataSourceOptions.find((item) => {
                    return item.value == row.dataSource
                })
                return io.label
            } else return ''
        },
        getFactoryList() {
            listAllFactory().then((res) => {
                this.factoryList = res.data
            })
        },
        batchAdd(operaType) {
            this.operaType = operaType
            this.templateVisibleAll = true
        },
        batchEdit(operaType) {
            this.operaType = operaType
            this.templateVisibleAll = true
        },
        templateDataCallback(data) {
            let path = ''
            if (this.operaType === 'add') {
                path = '/batchInspectionPlan/index/'
            } else {
                path = '/batchEditPlan/index/'
            }
            this.$router.push({
                path: path + encodeURIComponent(data.templateName),
            })
        },
        submitAudit() {
            this.$refs['auditForm'].validate((valid) => {
                if (valid) {
                    const { status, planRemark } = this.auditForm
                    getApproval({
                        ids: `${this.ids}`,
                        planRemark,
                        status,
                    }).then((res) => {
                        this.$modal.msgSuccess('审批成功!')
                        this.auditOpen = false
                        this.getList()
                    })
                }
            })
        },
        columnsCallback(planColumns) {
            console.log('planColumns', planColumns)
            localStorage.setItem('planColumns', JSON.stringify(planColumns))
            // Cookies.set('planColumns', planColumns, { expires: 100 })
            this.planKey++
        },
        materialTypeRemoteMethod(val, cb) {
            listMaterialType({ typeName: val }).then((res) => {
                cb(res.rows)
            })
        },
        handleMaterialTypeSelect(e, scope) {
            // this.dialogForm.materialType = e
            this.queryParams.materialType = e.typeName
            this.$forceUpdate()
        },
        updateStatus() {
            console.log(this.selectRows)
            if (this.selectRows.length !== 1) {
                this.$modal.msgWarning('请选择一个检验标准!')
                return
            }
            // if (!this.selectRows[0].processId) {
            //     this.$modal.msgWarning('当前检验标准没有流程Id!')
            //     return
            // }
            updateStatus({
                id: this.selectRows[0].id,
            }).then((res) => {
                this.getList()
            })
        },
        uploadCallback() {
            this.getList()
        },
        uploadCallback2() {
            this.getList()
        },
        uploadTemplateCallback() {
            this.getTemplateList()
        },
        async handleClick(e) {
            try {
                const formData = new FormData()
                formData.append('file', e.target.files[0])
                const res = await importPlan(formData)
                if (res.code == 200) {
                    this.$message.success('导入成功')
                    this.getList()
                    this.$refs['excel-upload-input'].value = ''
                }
            } catch (error) {
                this.$refs['excel-upload-input'].value = ''
            }
        },
        submitApproval: function () {
            this.approvalOpen = false
            this.approvalForm.ids = this.ids

            getSendBack(this.approvalForm).then((response) => {
                this.$modal.msgSuccess('退回成功')
                this.getList()
            })
        },
        handleImport() {
            this.templateVisible = true
            // this.$refs['excel-upload-input'].click()
        },
        importTemplate() {
            this.templateVisible2 = true
            // this.$refs['excel-upload-input'].click()
        },
        handleImport2() {
            this.templateVisible3 = true
            // this.$refs['excel-upload-input'].click()
        },
        handleImport3() {
            this.templateVisible33 = true
            this.$refs.templateVisible33.upload.title="多个导入"
            // this.$refs['excel-upload-input'].click()
        },
        statusfilter(row) {
            if (row.status) {
                let obj = this.dict.type.NYIQC_PROOFREAD_STATUS.find(
                    (item) => {
                        return item.value === row.status
                    }
                )
                if (obj) {
                    return obj.label
                } else {
                    return ''
                }
            } else {
                return ''
            }
        },
        handleEditTemplate(row) {
            console.log(row)
            this.$router.push({
                path:
                    '/editTemplate/index/' +
                    encodeURIComponent(row.templateName)+'?divisionName='+encodeURIComponent(row.divisionName),
            })
        },
        handleTemplateDetail(row) {
            this.$router.push({
                path:
                    '/templateDetail/index/' +
                    encodeURIComponent(row.templateName),
                query: {
                    isView: 1,
                },
            })
        },
        handleTemplateVersion(row) {
          getTemplateVersion(row.groupId).then((response) => {
            if (response.code == 200) {
              this.templateVersionTableList= response.data
            }
          })
          this.visible = true
        },
        handleSplit(row) {
            this.$modal.confirm('是否确认拆分？').then(() => {
                splitInspection({ id: row.id }).then((response) => {
                    if (response.code == 200) {
                        this.$modal.msgSuccess('拆分成功!')
                        this.getList()
                    }
                })
            })
        },
        handleCopyTemplate(row) {
            this.copyTemplateForm = { oldName: row.templateName }
            this.copyTemplateOpen = true
        },
        handleTemplateDelete(row) {
            this.$modal.confirm(this.$t('formValidation.doYouConfirmDeletion')).then(() => {
                templateDelete(row.templateName).then((response) => {
                    if (response.code == 200) {
                        this.$modal.msgSuccess(this.$t('tips.deleteSuccess'))
                        this.getTemplateList()
                    }
                })
            })
        },
        handleTemplate(row) {
            this.toTemplateOpen = true
            this.toTemplateModel = { planIds: row.id, itemId: row.itemId, templateName: null }
        },
        submitToTemplate() {
            planToTemplate(this.toTemplateModel).then((response) => {
                if (response.code == 200) {
                    this.$modal.msgSuccess('已成功转为模板!')
                    this.getTemplateList()
                    this.toTemplateOpen = false
                }
            })
        },
        handleCopy(row) {
            this.$modal.confirm('是否确认升版？').then(() => {
                planCopy(row.id).then((response) => {
                    if (response.code == 200) {
                        this.$modal.msgSuccess('升版成功!')
                        this.getList()
                    }
                })
            })
        },
        closeTab() {
            this.$router.push({
                path: '/inventoryManagement/additionalInspection',
            })
        },
        effectDateChange(e, scope) {
            if (parseInt(e) > 0) {
                this.planList[scope.$index].endDate = this.getNewDay(
                    scope.row.approvalTime,
                    e
                )
            }
        },
        getNewDay(dateTemp, days) {
            var dateTemp = dateTemp.split('-')
            //转换为MM-DD-YYYY格式
            var nDate = new Date(
                dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]
            )
            var millSeconds = Math.abs(nDate) + days * 24 * 60 * 60 * 1000
            var rDate = new Date(millSeconds)
            var year = rDate.getFullYear()
            var month = rDate.getMonth() + 1
            if (month < 10) month = '0' + month
            var date = rDate.getDate()
            if (date < 10) date = '0' + date
            return year + '-' + month + '-' + date
        },
        fileChange(e) {
            console.log(e)
        },
        drawerClose() {
            this.drawer = false
        },
        tableRowClassName({ row, rowIndex }) {
            console.log('rowIndex', rowIndex, row)
            if (row.isHighLight === true) {
                console.log('rowIndex', row)
                return 'rowHighLight' //若isHighLight为true，则使用“rowHighLight”样式
            } else {
                return ''
            }
        },
        getTemplateList() {
            listTemplate(this.queryParams).then((response) => {
                if (response.code == 200 && response.rows) {
                    this.templateList = response.rows
                    this.templateTotal = response.total
                    this.loading = false
                }
            })
        },
        /** 查询检验标准列表 */
        getList(flag) {
          this.loading = true
          if (flag) {
            divisionList(null).then((response) => {
              if (response.rows) {
                this.queryParams.divisionName = response.rows[0]?.divisionName
                inspectionPlan(this.queryParams).then((response) => {
                  if (response.code == 200 && response.rows) {
                    this.planList = response.rows
                    let selectRows = [...this.selectRows]
                    console.log(
                        'selectRows==============================',
                        selectRows
                    )
                    if (selectRows.length > 0) {
                      setTimeout(() => {
                        this.planList.forEach((io) => {
                          selectRows.forEach((ko) => {
                            console.log(
                                'true=============================='
                            )
                            if (io.id === ko.id) {
                              this.$refs.multipleTable.toggleRowSelection(
                                  io,
                                  true
                              )
                            }
                          })
                        })
                      }, 300)
                    }
                    this.total = response.total
                    this.loading = false
                    this.tableHeight = this.isFold
                        ? 'calc(100vh - 358px)'
                        : 'calc(100vh - 498px)'
                  }
                })
              }
            })
          } else {
            inspectionPlan(this.queryParams).then((response) => {
              if (response.code == 200 && response.rows) {
                this.planList = response.rows
                let selectRows = [...this.selectRows]
                console.log(
                    'selectRows==============================',
                    selectRows
                )
                if (selectRows.length > 0) {
                  setTimeout(() => {
                    this.planList.forEach((io) => {
                      selectRows.forEach((ko) => {
                        console.log(
                            'true=============================='
                        )
                        if (io.id === ko.id) {
                          this.$refs.multipleTable.toggleRowSelection(
                              io,
                              true
                          )
                        }
                      })
                    })
                  }, 300)
                }
                this.total = response.total
                this.loading = false
                this.tableHeight = this.isFold
                    ? 'calc(100vh - 358px)'
                    : 'calc(100vh - 498px)'
              }
            })
          }
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.form = {
                dictId: undefined,
                dictName: undefined,
                dictType: undefined,
                status: '0',
                remark: undefined,
            }
            this.queryParams.id = null
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList(false)
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.queryParams.id = null
            this.dateRange = []
            this.resetForm('queryForm')
            this.handleQuery()
        },
        resetTemplate() {
            this.dateRange = []
            this.resetForm('queryForm2')
            this.queryParams = {
                pageSize: 10,
                pageNum: 1,
            }
            this.getTemplateList()
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.$router.push({
                path: '/addInspectionPlan/index/' + 0,
                query: {
                    isTemplate: 1,
                },
            })
        },
        handleAddTemplate() {
            this.$router.push({ path: '/addTemplate/index/' + 0 })
        },
      handleExportExcel() {
        if (this.templateNames.length ==0) {
          this.$modal.msgWarning('请选择一条数据导出!')
          return
        }
        this.postDownload(
            'ny-iqc/checkItem/exportInspectionTemplate',
            {templateNameList: this.templateNames},
            `type_${new Date().getTime()}.zip`,
            'application/json'
        )
      },
      handlePush() {
        if (this.templateNames.length ==0) {
          this.$modal.msgWarning('请选择数据')
          return
        }
        this.$modal
            .confirm('请知悉：一键推送后，当前模版对应的物料分类下的所有物料编号都会自动更新检验项')
            .then(() => {
              push(this.templateNames).then((response) => {
                this.$modal.msgSuccess(this.$t('推送成功！'))
              })
            })
            .catch(() => {})
      },

        // 多选框选中数据
        handleSelectionChange(selection) {
            this.templateNames = selection.map((item) => item.templateName)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        handlePlanChange(selection) {
            this.selectRows = selection
            this.ids = selection.map((item) => item.id)
            console.log('this.ids', this.ids)
            this.planList.forEach((io, index) => {
                console.log('includes', this.ids.includes(io.id))
                if (this.ids.includes(io.id)) {
                    io.isHighLight = true
                } else {
                    io.isHighLight = false
                }
            })
            this.single = selection.length != 1
            this.multiple = !selection.length
        },

        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset()
            const dictId = row.dictId || this.ids
            getType(dictId).then((response) => {
                this.form = response.data
                this.open = true
                this.title = '修改字典类型'
            })
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$modal.msgSuccess('提交成功!')
            this.$router.push({
                path: '/inventoryManagement/additionalInspection',
            })
            // this.$refs['addForm'].validate((valid) => {
            //   if (valid) {
            //     this.$modal.msgSuccess("提交成功!");
            //     this.addInspectionExemption = false;
            //   } else {
            //     console.log('error submit!!');
            //     return false;
            //   }
            // });
        },
        submitCopyTemplate() {
            this.copyTemplateOpen = false
            templateCopy(this.copyTemplateForm).then((res) => {
                this.$modal.msgSuccess('复制成功!')
                this.getTemplateList()
            })
        },
        /** 发起检验提交 */
        submitAddForm: function () {
            this.$modal.msgSuccess('发起成功!')
            this.addInspection = false
        },

        /** 删除按钮操作 */
        handleDelete(row) {
            this.$modal.confirm(this.$t('formValidation.doYouConfirmDeletion')).then(() => {
                deletePlan(row.id).then((res) => {
                    this.$modal.msgSuccess(this.$t('tips.deleteSuccess'))
                    this.getList()
                })
            })
        },
        handleBatchDelete() {
            console.log(this.ids)
            if (this.ids.length === 0) {
                this.$modal.msgWarning('请至少选择一条删除!')
                return
            }
            this.$modal.confirm(this.$t('formValidation.doYouConfirmDeletion')).then(() => {
                deletePlan(this.ids.join(',')).then((res) => {
                    this.$modal.msgSuccess(this.$t('tips.deleteSuccess'))
                    this.getList()
                })
            })
        },
        handleSubmit() {
            console.log(this.ids)
            if (this.ids.length === 0) {
                this.$modal.msgWarning('请选择一条进行提交!')
                return
            }
            this.submitOpen = true
            // this.$modal.confirm('是否确认提交？').then(() => {
            //     getSubmit(this.ids).then((res) => {
            //         this.$modal.msgSuccess('确认成功!')
            //         this.getList()
            //     })
            // })
        },
        handleApprove() {
            console.log(this.ids)
            if (this.ids.length === 0) {
                this.$modal.msgWarning(this.$t('formValidation.pleaseSelectOneForApproval'))
                return
            }
            getApprovalInspectionCheck({ ids: this.ids.join(',') }).then(
                (response) => {
                    this.auditOpen = true
                }
            )
            // this.$modal.confirm('是否确认审批？').then(() => {
            //     getApproval(this.ids).then((res) => {
            //         this.$modal.msgSuccess('审批成功!')
            //         this.getList()
            //     })
            // })
        },
        handleRevokeApprove() {
            
            
            console.log(this.selectRows)
            if (this.selectRows.status == '1') {
                this.$modal.msgWarning(this.$t("formValidation.cannotBeRevoked"))
                return
            }
            this.$modal.confirm(this.$t('formValidation.whetherToConfirmTheWithdrawalOfApproval')).then(() => {
                revokeApprove({ids: this.ids}).then((response) => {
                if (response){
                    this.$modal.msgSuccess('撤销成功!')
                    this.getList()
                    }
                })
            })
        },
        handleReturn() {
            if (this.ids.length === 0) {
                this.$modal.msgWarning('请选择一条进行驳回!')
                return
            }
            this.approvalOpen = true
        },
        handleCheckout() {
            console.log(this.ids)
            if (this.ids.length === 0) {
                this.$modal.msgWarning('请选择一条进行校对!')
                return
            }
            this.$modal.confirm('是否确认完成校对？').then(() => {
                getProofread(this.ids).then((res) => {
                    this.$modal.msgSuccess('校对成功!')
                    this.getList()
                })
            })
        },
        /**
         * 历史版本按钮事件
         */
         handleHistory(){
            if (Array.isArray(this.selectRows) && this.selectRows.length == 1) {
                this.historyQueryParams.pageNum = 1
                this.historyQueryParams.materialCode = this.selectRows[0]?.materialCode
                this.historyQueryParams.factoryCode = this.selectRows[0]?.factoryCode
                this.historyOpen = true
                this.getHistoryList()
                return
            }
            this.$modal.msgWarning(this.$t('inspectionManagement.pleaseSelectOne'))
        },
        getHistoryList(){
            this.historyLoading = true
            getHistoryPlan(this.historyQueryParams).then((response) => {
                if (response.code == 200 && response.rows) {
                    this.planHistoryList = response.rows
                    this.historyTotal = response.total
                    this.historyLoading = false
                    this.tableHeight = this.isFold ? 'calc(100vh - 358px)' : 'calc(100vh - 498px)'
                }
            })
        },
        /** 查看按钮操作 */
        handleView(row) {
            this.$router.push({
              path: '/inspectionDetail/index/' + row.id,
                query: {
                    isView: 1,
                },
            })
        },
        /** 编辑按钮操作 */
        handleEdit(row) {
            inspectionPlanEditCheck({ id: row.id }).then((res) => {
                if (res.code) {
                    this.$router.push({
                        path: '/editInspectionPlan/index/' + row.id,
                        query: {
                            isTemplate: 1,
                        },
                    })
                }
            })
        },
        /** 关闭抽屉操作 */
        handleClose(row) {
            this.drawer = false
        },
        handleExportList() {
            this.download(
                'ny-iqc/inspectionPlan/exportList',
                {
                    ...this.queryParams,
                },
                `type_${new Date().getTime()}.xlsx`
            )
        },
        /** 导出按钮操作 */
        handleExport() {
            if (this.ids.length !== 1) {
                this.$modal.msgWarning(this.$t('formValidation.pleaseSelectDataExport'))
                return
            }
            this.otherDownload(
                'ny-iqc/inspectionPlan/export',
                { ids: this.ids.join(',') },
                `type_${new Date().getTime()}.zip`
            )
        },
        handleExportTemplate() {
            this.download(
                'ny-iqc/checkItem/export',
                {
                    ...this.queryParams,
                },
                `type_${new Date().getTime()}.xlsx`
            )
        },
        /** 刷新缓存按钮操作 */
        handleRefreshCache() {
            refreshCache().then(() => {
                this.$modal.msgSuccess('刷新成功')
            })
        },
    },
}
</script>
<style lang="scss" scoped>
::v-deep .el-card {
    padding-top: 20px;
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    padding-bottom: 20px;
}
::v-deep .el-aside {
    padding: 0;
    margin-bottom: 0;
}
.content-style {
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 2px;
    background-color: white;
    margin-top: 10px;
}
::v-deep .el-button-group .selBtn {
    background: #fff;
    border: 1px solid #0b7be3;
    color: #0b7be3;
}
::v-deep .el-button-group .unselBtn {
    background: #fff;
    border: 1px solid #ededf2;
    color: #666666;
}
.header-left {
    float: left;
    font-size: 14px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
    line-height: 40px;
    display: flex;
    justify-content: center;
    border-bottom: 2px solid #0b7be3;
}
.header-right {
    float: right;
}
.container-header {
    float: left;
    width: 100%;
    border-bottom: 1px solid #ededf2;
    padding-left: 12px;
}
.container-table {
    float: left;
    margin-top: 6px;
    width: 100%;
    overflow: auto;
}
.mb8 {
    float: left;
    margin-top: 6px;
    width: 100%;
}
.drawer-footer {
    display: flex;
    position: relative;
    z-index: 9999;
    bottom: -40px;
    height: 40px;
    justify-content: center;
    width: 100%;
}
.hign-line {
    position: relative;
    left: -8px;
    top: 14px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid #0b7be3;
    float: left;
}
.drawer-close {
    background: #f7f8fa;
    border-color: #f7f8fa;
}
.submit-footer {
    height: 52px;
    background: #ffffff;
    box-shadow: 0px -5px 5px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px 4px 0px 0px;
    position: fixed;
    z-index: 9;
    bottom: 0px;
    width: 100%;
    left: 0px;
    display: flex;
    justify-content: center;
    align-items: center;
}
.samplingPercent {
    position: absolute;
    z-index: 9;
    right: 20px;
}
::v-deep .el-card {
    padding-top: 0px;
    overflow: auto;
}
::v-deep .el-form-item__label {
    font-weight: 400;
    color: #999999;
}
.search {
    background: #20b09f;
    border-color: #20b09f;
}
::v-deep .rowHighLight {
    background: oldlace;
}
</style>
